package com.kingsystem.kingteachermarks_backend.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kingsystem.kingteachermarks_backend.entity.ViewWorkPerformance;
import com.kingsystem.kingteachermarks_backend.mapper.ViewWorkPerformanceMapper;
import com.kingsystem.kingteachermarks_backend.service.impl.ViewSystemUserServiceImpl;
import com.kingsystem.kingteachermarks_backend.service.impl.ViewWorkPerformanceServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.swing.text.View;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author leiyue_yao
 * @since 2025-08-07
 */
@Controller
@RequestMapping("/viewWorkPerformance")
@CrossOrigin
public class ViewWorkPerformanceController {
    @Autowired
    private ViewWorkPerformanceMapper vwpm;

    @Autowired
    private ViewWorkPerformanceServiceImpl vwpi;

    @PostMapping("/getWorkPerformanceByTimeDuration")
    @ResponseBody
    public List<ViewWorkPerformance> getWorkPerformanceByTimeDuration(
            @RequestParam("time_start") String time_start,
            @RequestParam("time_end") String time_end,
            @RequestParam("record_user_id") String record_user_id){


        QueryWrapper<ViewWorkPerformance> qw = new QueryWrapper<>();
        qw.ge("finish_time", time_start)
                .le("finish_time",time_end)
                .eq("record_user_id", record_user_id)
                .eq("flag_del",0)
                .orderByDesc("finish_time");

        List<ViewWorkPerformance> li = vwpi.list(qw);

        return li;
    }

    @PostMapping("/getWorkPerformanceById")
    @ResponseBody
    public ViewWorkPerformance getWorkPerformanceById(
            @RequestParam("workPerformanceId") String workPerformanceId){


        QueryWrapper<ViewWorkPerformance> qw = new QueryWrapper<>();
        qw.eq("tableKey", workPerformanceId);

        return vwpi.getOne(qw);
    }
}
